<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <FilterTable
      ref="table"
      columnsRef="testindex"
      :isExportExcel2="true"
      exportFileName="配件发运单.xlsx"
      :columns="columns"
      :fetchapi="fetchApi"
      :isSelectColumn="false"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
    </FilterTable>

    <Drawer
      :visible.sync="visibleDrawer"
      title="配件发运单详情"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
       >
      <info-model v-model="initData" @close="infoClose" />
    </Drawer>
  </div>
</template>

<script>
import { ddztArr } from '../query/constant';
import infoModel from './info';
import { dictionary } from '@/utils/dictMixin';
import { getShipmentData } from '@/api/partsmanage/shipment/query';
export default {
  name: 'shipmentreceiveindex',
  mixins: [dictionary],
  components: {
    infoModel
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns(),
      fetchApi: getShipmentData,
      visibleDrawer: false,
      dealerCode: '',
      initData: {}
    }
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    Object.assign({ xsdjzt: 'F' }, this.fetchParams)
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: 'SAP发运单号:',
          fieldName: 'bsysdh'
        },
        {
          type: 'RANGE_DATE',
          label: '发运日期',
          fieldName: 'bsfyrq',
          valueFormat: 'yyyy-MM-dd',
          initialValue: [],
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '配件代码:',
          fieldName: 'bjxmbh'
        },
        {
          type: 'INPUT',
          label: '配件名称:',
          fieldName: 'bjzwmc'
        },
        {
          type: 'INPUT',
          label: '发运单号:',
          fieldName: 'bsydxh'
        },
        // {
        //   type: 'INPUT',
        //   label: '订单号:',
        //   fieldName: 'bscsdj'
        // }
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.detailHandle(props.row, 'show')}>
                  明细
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '签收状态',
          dataIndex: 'xsdjzt',
          sorter: true,
          dictItems: ddztArr
        },
        {
          title: '经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
        },
        {
          title: '经销商名称',
          dataIndex: 'sasa1',
          sorter: true,
          width: 200
        },
        {
          title: '签收日期',
          dataIndex: 'bsqcrq',
          sorter: true,
        },
        {
          title: '发运单号',
          dataIndex: 'bsydxh',
          sorter: true,
        },
        {
          title: 'SAP发运单号',
          dataIndex: 'bsysdh',
          sorter: true,
          width: 180
        },
        // {
        //   title: '订单号',
        //   dataIndex: 'bscsdj',
        //   sorter: true,
        //   width: 180
        // },
        {
          title: '交货单号',
          dataIndex: 'hxddhm',
          sorter: true,
          width: 180
        },
        {
          title: '发运日期',
          dataIndex: 'bsfyrq',
          sorter: true,
        },
        {
          title: '发货总数量',
          dataIndex: 'bsfysl',
          sorter: true,
        },
        {
          title: '签收数量',
          dataIndex: 'qssl',
          sorter: true,
        },
        {
          title: '差异数量',
          dataIndex: 'bszssl',
          sorter: true,
        },
        // {
        //   title: '物流公司',
        //   dataIndex: 'index9',
        //   sorter: true,
        // },
        {
          title: '预计到货日期',
          dataIndex: 'bsyjdd',
          sorter: true,
        },
        {
          title: '发运方式',
          dataIndex: 'btyslx',
          sorter: true,
        },
      ]
    },
    changeHandle(val) {
      // this.fetchParams = Object.assign({}, val);
      // this.fetchParams = Object.assign({ xsdjzt: 'F' }, this.fetchParams)
      this.fetchParams = Object.assign({}, val, { xsdjzt: 'F', xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectData(val) {
      this.tableData = val;
    },
    detailHandle(row, type) {
      this.initData =  {
        type: type,
        data: row,
        id:1001
      }; //行id
      this.visibleDrawer = true;
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
  }
}
</script>
